package com.zy.qudadid.presenter;

import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.IndexSGoView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/9/20.
 */
public class IndexSGoPresenter extends BasePresenterImp<IndexSGoView> {
    public void PublishOrder(String data){
        Subscription subscription = Net.getService()
                .PublishOrder(data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code == Const.OK) {
                            view.success();
                        } else {
                            view.error(res.message);
                        }
                    }
                });

        addSubscription(subscription);
    }

//    c=user&a=getfee_from_mile&args=
    public void getMoney(String data){
        Subscription subscription = Net.getService()
                .GetMoney(data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code == Const.OK) {
                            view.successmile(res.datas.toString());
                        } else {
                            view.errormile();
                        }
                    }
                });

        addSubscription(subscription);
    }
}
